<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>版本信息编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
    <style>
        .zsIMG {
            width: 100px;
            height: 100px;
            cursor: pointer;
        }
    </style>
</head>

<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">

    <form class="layui-form layui-form-pane" id="formsubmit" style="width: 500px;margin:20px auto"
          action="/after/game/zpJiangpinAddSave">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>所有勾选的奖品的概率值累加，不能超过1000;
                若累加概率小于1000,则将加大谢谢惠顾的概率</legend>
        </fieldset>
        <div class="layui-form-item" id="wai_url">
            <label class="layui-form-label">谢谢惠顾</label>
            <div class="layui-input-block">
                <input type="checkbox" lay-skin="primary" title="是否参与转盘奖品" checked disabled>
            </div>
            <div class="layui-input-block" style="display: flex;align-items: center">
                <p>第一次概率:</p>
                <input style="width: 100px" type="text" class="layui-input" value="自动填补" disabled>
            </div>
            <div class="layui-input-block" style="display: flex;align-items: center">
                <p>后&nbsp;续&nbsp;概&nbsp;率&nbsp;:</p>
                <input style="width: 100px" type="text" class="layui-input" value="自动填补" disabled>
            </div>
        </div>

        <#list  list as gl>
            <#if gl.leixing!=5>
        <div class="layui-form-item" id="wai_url">
            <label class="layui-form-label">${gl.jpname}</label>
            <div class="layui-input-block">
                <input type="checkbox" lay-filter="levelM" value="${(gl.id)!''}" name="sex" lay-skin="primary"
                       title="是否参与转盘奖品" <#if gl.canyustate==1>checked</#if>>

            </div>

            <div class="layui-input-block" style="display: flex;align-items: center">
                <p>第一次概率:</p>
                <input style="width: 100px" type="number" min="0" maxlength="1000" id="oneGailv${(gl.id)!''}" class="layui-input"
                       value="${gl.onegailv!''}">
            </div>
            <div class="layui-input-block" style="display: flex;align-items: center">
                <p>后&nbsp;续&nbsp;概&nbsp;率&nbsp;:</p>
                <input style="width: 100px" type="number" min="0"  maxlength="1000" id="laterGailv${(gl.id)!''}" class="layui-input"
                       value="${gl.latergailv!''}">
            </div>
        </div>
            </#if>
        </#list>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">&emsp;保存&emsp;
                </button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
                    &emsp;返回&emsp;
                </button>
            </div>
        </div>
        <input type="hidden" id="chushiGlValue" name="chushiGlValue">

    </form>
</div>
<script>

    layui.use('form', function () {
        let $ = layui.$;
        var form = layui.form;
        form.render();

        $.fn.extend({
            serializeObject: function () {
                var obj = {}; //声明一个对象
                $.each(this.serializeArray(), function (index, field) {
                    obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                })
                return obj;
            }
        });

        form.on('select(jiangpinType)', function (data) {
            var message = parseInt($("select[name=jiangpinType").val());
            console.log(message)
            if (message === 1) {
                $("#huiyuan").css("display", "block");
                $("#xianjin").css("display", "none");
                $("#jinbi").css("display", "none");
                $("#zpJiangliTypeValue").val(1);
            } else if (message === 2) {

                $("#huiyuan").css("display", "none");
                $("#xianjin").css("display", "block");
                $("#jinbi").css("display", "none");
                $("#zpJiangliTypeValue").val(2);

            } else if (message === 3) {
                $("#huiyuan").css("display", "none");
                $("#xianjin").css("display", "none");
                $("#jinbi").css("display", "block");
                $("#zpJiangliTypeValue").val(3);

            }


        });


        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;

        form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {
            var type = parseInt($("#zpJiangliTypeValue").val());
            if ($("#jpName").val() == '') {
                layer.msg("奖品名不能为空", {icon: 2, time: 1000});
                return false;
            }
            if (type === 2) {
                if ($("#jinbiNum").val() == '') {
                    layer.msg("现金不能为空", {icon: 2, time: 1000});
                    return false;
                }
            }
            var values = "";
            if (type === 1) {
                values = $("#huiyuanNum").val();
            } else if (type === 2) {
                values = $("#xianjinNum").val();
            } else if (type === 3) {
                values = $("#jinbiNum").val();
            }
            var states = "";
            if ($("#state").prop("checked")) {
                states = 1
            } else {
                states = 2
            }

            //获取选中的值
            var arr = new Array();
            $("input:checkbox[name='sex']:checked").each(function (i) {
                arr[i] = $(this).val();
            });
            data.field.like = arr.join(",");//将数组合并成字符串
            var values = data.field.like;
            var valuess = values.split(",");
            var chushiGl = 0;
            var laterGl = 0;
            var chushiGlValue = "";
            if (!(valuess.length === 1 && valuess[0] === '')) {
                for (var i = 0; i < valuess.length; i++) {
                    chushiGl += parseFloat($("#oneGailv" + valuess[i]).val());
                    laterGl += parseFloat($("#laterGailv" + valuess[i]).val());
                    chushiGlValue += valuess[i] + "α" + parseFloat($("#oneGailv" + valuess[i]).val()) + "β" + parseFloat($("#laterGailv" + valuess[i]).val()) +"γ1,"
                }
                if (chushiGl === 0) {
                    layer.msg("第一次总概率不能为0", {icon: 2, time: 1000});
                    return false;
                }
                if (laterGl === 0) {
                    layer.msg("后续总概率不能不能为0", {icon: 2, time: 1000});
                    return false;
                }
                if (chushiGl > 1000) {
                    layer.msg("第一次总概率不能大于1000", {icon: 2, time: 1000});
                    return false;
                }
                if (laterGl > 1000) {
                    layer.msg("后续总概率不能大于1000", {icon: 2, time: 1000});
                    return false;
                }
                $("#chushiGlValue").val(chushiGlValue);
            }else{
                $("#chushiGlValue").val("");
            }

            var chushiGlValues=$("#chushiGlValue").val();

            //获取未选中的值
            var arrs = new Array();
            $("input:checkbox[name='sex']:not(:checked)").each(function (i) {
                arrs[i] = $(this).val();
            });
            data.field.like = arrs.join(",");//将数组合并成字符串
            var valueN = data.field.like;
            var valueNN = valueN.split(",");
            if (!(valueNN.length === 1 && valueNN[0] === '')) {
                for (var i = 0; i < valueNN.length; i++) {
                    chushiGlValues += valueNN[i] + "α" + parseFloat($("#oneGailv" + valueNN[i]).val()) + "β" + parseFloat($("#laterGailv" + valueNN[i]).val()) + "γ0,"
                }
                $("#chushiGlValue").val(chushiGlValues);
            }

            console.log($("#chushiGlValue").val())
            layer.confirm('确认要保存吗？', function (index) {

                   ajaxPost($, "/after/game/zpGailvSettingSave", {
                       chushiGlValue: $("#chushiGlValue").val()
                    }, function (data) {
                        if (data.code === 0) {
                            layer.msg("抽奖概率设置成功", {icon: 1, time: 2000});
                            setTimeout(function () {
                                location.reload();
                            }, 1000);
                        } else {
                            layer.msg("抽奖概率设置失败", {icon: 2, time: 2000});
                        }

                    });

            });

        });

    });

    //统计概率
    function statisticalProbability(values) {


    }


</script>
</body>

</html>